﻿using System.Diagnostics;
using NetwordEnabler;

namespace VMwareEnabler.Model
{
    public class Model
    {
        private static readonly string[] SERVICES = {"VMAuthdService", "VMnetDHCP", "\"VMware NAT Service\"", "VMUSBArbService"};

        private static readonly string[] NETWORK = {Network.Default.Network1, Network.Default.Network2};

        public static void Enable()
        {
            
            ServiceEnabler.ServiceEnabler.Enable(SERVICES[0]);
            ServiceEnabler.ServiceEnabler.Enable(SERVICES[1]);
            ServiceEnabler.ServiceEnabler.Enable(SERVICES[2]);
            ServiceEnabler.ServiceEnabler.Enable(SERVICES[3]);

            NetworkEnabler.Enable(NETWORK[0]);
            NetworkEnabler.Enable(NETWORK[1]);
        }

        public static void Disable()
        {
            ServiceEnabler.ServiceEnabler.Disable(SERVICES[0]);
            ServiceEnabler.ServiceEnabler.Disable(SERVICES[1]);
            ServiceEnabler.ServiceEnabler.Disable(SERVICES[2]);
            ServiceEnabler.ServiceEnabler.Disable(SERVICES[3]);

            NetworkEnabler.Disable(NETWORK[0]);
            NetworkEnabler.Disable(NETWORK[1]);
        }

        public static bool Check()
        {
            bool allGood = true;

            ViewModel.MainViewModel mvm = new ViewModel.ViewModelLocator().Main;
            allGood &= mvm.natenabled = ServiceEnabler.ServiceEnabler.CheckStatus(SERVICES[0]);
            allGood &= mvm.usbenabled = ServiceEnabler.ServiceEnabler.CheckStatus(SERVICES[1]);
            allGood &= mvm.dhcpenabled = ServiceEnabler.ServiceEnabler.CheckStatus(SERVICES[2]);
            allGood &= mvm.authenabled = ServiceEnabler.ServiceEnabler.CheckStatus(SERVICES[3]);

            allGood &= mvm.net1enabled = NetworkEnabler.Check(NETWORK[0]);
            allGood &= mvm.net2enabled = NetworkEnabler.Check(NETWORK[1]);

            Debug.WriteLine(allGood);
            return allGood;
        }

        public static void Launch()
        {
            VMLauncher.Instance.Launch();
        }

    }
}
